home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / system / chips.zip / CHIPS.ASM next >
Assembly Source File  |  1988-01-01  |  10KB  |  216 lines

  1. ;   calling convention:
  2. ;
  3. ;       int chips( void );
  4. ;
  5. ;   returns:
  6. ;
  7. ;       tucked away neatly in your AX....
  8. ;
  9. ;       you get back   8x if an 8088/8086
  10. ;                     18x if an 80186/80188
  11. ;                     28x if an 80286
  12. ;                     38x if an 80386
  13. ;                     20x for a NEC V20/V30
  14. ;                AND
  15. ;                     xx0 if NO NDP is found
  16. ;                     xx1 if an 8087
  17. ;                     xx2 if an 80287
  18. ;                     xx3 for an 80387
  19. ;
  20. ;   OR.....
  21. ;
  22. ;   >>> A return of 280 means you got an 80286 machine with no NDP, <<<
  23. ;   >>> 383 means you have an 80386/80387 rig to work with, and a   <<<
  24. ;   >>> return of 81 sez that you have 8088/8086 CPU with an 8087.  <<<
  25. ;   >>> A 200 tells you that you got an NEC V20/V30 without an NDP. <<<
  26. ;   >>> ETC., Etc., etc.                                            <<<
  27. ;
  28. ;   NOTE:
  29. ;
  30. ;       There are lotsa ways of handling the way this function returns
  31. ;       it's data.  For my purposes, I have elected this one because
  32. ;       it requires only int arithmetic on the caller's end to extract
  33. ;       all the info I need from the return value.  I think that I'm
  34. ;       well enough 'commented' in the following code so that you will
  35. ;       be able to tinker and Putz until you find the best return tech-
  36. ;       nique for Ur purposes without having to reinvent the wheel.
  37. ;
  38. ;     >>>>        Please see TEST.C, enclosed in this .ARC.      <<<<
  39. ;
  40. ;   REFERENCES:
  41. ;
  42. ;     _chips is made up of two PROC's, cpu_type and ndp_type.
  43. ;
  44. ;       cpu_type is based on uncopyrighted, published logic by
  45. ;         Clif (that's the way he spells it) Purkiser of Intel -
  46. ;         Santa Clara.
  47. ;
  48. ;       ndp_type is adopted from Ted Forgeron's article in PC
  49. ;         Tech Journal, Aug '87 p43.
  50. ;
  51. ;     In the event of subsequent republication of this function,
  52. ;       please carry forward reference to these two gentlemen as
  53. ;       original authors.
  54. ;
  55. ;       Copr. 1987      Pat Shea - Psi! (that Copr. is on there cuz my
  56. ;                                        lawyer sez I should, but feel
  57. ;                                        free to hack away!!!    pats.)
  58. ;
  59. ;       Update:   1/1/88 - changed this code slightly so that it is
  60. ;                          compilable using MASM 5.0, and the test.c
  61. ;                          file using MSC 5.0. <Albert Stein>
  62. .MODEL SMALL
  63. .CODE
  64.         PUBLIC  _chips
  65.  
  66. _chips         PROC
  67.  
  68. control dw     0              ; control word needed for the NDP test
  69.  
  70.         push   BP             ; save where Ur at
  71.         mov    BP,SP          ;   going in.....
  72.  
  73.         push   DI
  74.         push   SI
  75.         push   CX             ; not really needed for MSC but kinda
  76.                               ;   nice to do cuz someone else might
  77.                               ;   want to use the function and we do
  78.                               ;   use CX later on
  79.  
  80.         call   cpu_type       ; find out what kinda CPU you got and
  81.                               ;   and save it in DX for future reference
  82.         call   ndp_type       ; check for math coprocessor (NDP) type
  83.                               ;   and hold that result in AX
  84.  
  85.         add    AX,DX          ; add the two results together and hold
  86.                               ;   'em in AX for Ur return to the caller
  87.  
  88.         pop    CX             ; put things back the way that you
  89.         pop    SI             ;   found 'em when you started this
  90.         pop    DI             ;   little drill off.....
  91.         pop    BP
  92.                               ; AND
  93.         ret                   ; go back to where you came from....
  94.                               ;   ( ===>  the calling program )
  95.                               ;   with Ur results sittin' in AX !!
  96. _chips         endp
  97.  
  98.  
  99. cpu_type       PROC
  100.  
  101.         pushf                 ; pump Ur flags register onto the stack
  102.         xor    DX,DX          ; blow out Ur DX and AX to start off
  103.         xor    AX,AX          ;   with a clean slate
  104.         push   AX             ; put AX on the stack
  105.         popf                  ; bring it back in Ur flags
  106.         pushf                 ; try to set bits 12 thru 15 to a zero
  107.         pop    AX             ; get back Ur flags word in AX
  108.         and    AX, 0f000h     ; if bits 12 thru 15 are set then you got
  109.         cmp    AX, 0f000h     ;   an Intel 8018x or a 808x or maybe even
  110.         jz     dig            ;   a NEC V20/V30 ??? - gotta look more...
  111.  
  112. ; OTHERWISE....
  113. ;   Here's the BIG one.... 'tells the difference between an 80286 and
  114. ;   an 80386 !!
  115.  
  116.         mov    AX, 07000h     ; try to set FLAG bits 12 thru 14
  117.                               ;   - NT, IOPL
  118.         push   AX             ; put it onto the stack
  119.         popf                  ;   and try to pump 07000H into Ur flags
  120.         pushf                 ; push Ur flags, again
  121.         pop    AX             ;   and bring back AX for a compare
  122.         and    AX,07000h      ; if Ur bits 12 thru 14 are set
  123.         jnz    got386         ;   then Ur workin' with an 80386
  124.         mov    DX, 0280       ; save 280 in DX cuz it's an 80286
  125.         jmp    SHORT CPUbye   ;   and bail out
  126.  
  127. got386: mov    DX, 0380       ; save 380 in DX cuz it's an Intel 80386
  128.         jmp    SHORT CPUbye   ;   and bail out
  129.  
  130. ; here's we try to figger out whether it's an 80188/80186, an 8088/8086
  131. ;   or an NEC V20/V30 - 'couple of slick tricks from Clif Purkiser.....
  132.  
  133. dig:    mov    AX, 0ffffh     ; load up AX
  134.         mov    CL, 33         ; HERE's the FIRST TRICK.... this will
  135.                               ;   shift everything 33 times if it's
  136.                               ;   8088/8086, or once for a 80188/80186!
  137.         shl    AX, CL         ; on a shift of 33, all bits get zeroed
  138.         jz     digmor         ;   out so if anything is left ON it's
  139.                               ;   gotta be an 80188/80186
  140.         mov    DX,0180        ; save 180 in DX cuz it's an 80188/80186
  141.         jmp    SHORT CPUbye   ;   and bail out
  142.  
  143. digmor: xor    AL,AL          ; clean out AL to set ZF
  144.         mov    AL,40h         ; ANOTHER TRICK.... mul on an NEC duz NOT
  145.         mul    AL             ;   effect the zero flag BUT on an Intel
  146.         jz     gotNEC         ;   8088/8086, the zero flag gets thrown
  147.         mov    DX,0080        ; 80 into DX cuz it's an Intel 8088/8086
  148.         jmp    SHORT CPUbye   ;   and bail out
  149.  
  150. gotNEC: mov    DX,0200        ; it's an NEC V20/V30 so save 200 in DX
  151.  
  152. CPUbye: popf                  ; putchur flags back to where they were
  153.         ret                   ;   and go back to where you came from
  154.                               ;   (i.e., ===>  _chips) with the CPU type
  155.                               ;   tucked away in DX for future reference
  156. cpu_type       endp
  157.  
  158. ; Check for an NDP.
  159. ;
  160. ; >>>>NOTE:  If you are using an MASM version < 5.0, don't forget to
  161. ; use the /R option or you will bomb cuz of the coprocessor instruc-
  162. ; tions.  /R is not needed for version 5.0.<<<<<<<<<<<<<<<<<<<<<<<<<
  163.  
  164. ndp_type       PROC
  165.  
  166. do_we:  fninit                          ; try to initialize the NDP
  167.         mov    byte ptr control+1,0     ; clear memory byte
  168.         fnstcw control                  ; put control word in memory
  169.         mov    AH,byte ptr control+1    ; iff AH is 03h, you got
  170.         cmp    AH,03h                   ;   an NDP on board !!
  171.         je     chk_87                   ; found somethin', keep goin'
  172.         xor    AX,AX                    ; clean out AX to show a zero
  173.         jmp    SHORT NDPbye             ;   return (i.e., no NDP)
  174.  
  175. ; 'got an 8087 ??
  176.  
  177. chk_87: and    control,NOT 0080h        ; turn ON interrupts (IEM = 0)
  178.         fldcw  control                  ; load control word
  179.         fdisi                           ; turn OFF interrupts (IEM = 1)
  180.         fstcw  control                  ; store control word
  181.         test   control,0080h            ; iff IEM=1, 8087
  182.         jz     chk287                   ; 'guess not!  March on....
  183.         mov    AX,0001                  ; set up for a 1 return to
  184.         jmp    SHORT ND